/**
 * Created by wanthering on 2017/8/18.
 */
'use strict'

// if(localStorage.uploadJwt === 'filahfiuenfc&fdkfjaom_eiu'){
//   $('.login-wrapper').hide()
// }

// if(localStorage.uploadJwt){

var newId = $('mata[name=newId]').attr('content')
var id = $('input[name=id]').val()
var lessonId = (id && id!=='' && id!==0)?id:newId

  $.ajax('/checkJwt',{
    method: 'POST',
    type:'json',
    data:{
      jwt:localStorage.uploadJwt
    },
    success: function(d){
      if(d && d.success){
        $('#afterClass').attr('href','/admin/lesson/new/'+lessonId+'/'+localStorage.uploadJwt)
      }else{
        $('.login-wrapper').show()
      }
    }
  })





$('#login').click(function(){
  let username = $('#username').val()
  let password = $('#password').val()
  $.ajax('/login',{
    method: 'POST',
    type: 'json',
    data: {
      username:username,
      password:password
    },
    success: function(d){
      if(d && d.success){
        console.log(d.jwt)
        localStorage.uploadJwt = d.jwt
        $('.login-wrapper').hide()
      }
  }
  })

})